﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 短句 数据类
    /// </summary>
    public class SysPhrase
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SysPhrase()
        {
        }
        /// <summary>
        /// 获取最新短句 部分字段 FPhrase,FURL
        /// <creator>wangl</creator>
        /// <date>2013-09-04</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>实体类</returns>
        public Model.SysPhrase GetModelPart(string entityNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FPhrase,FURL from t_SysPhrase ");
            strSql.Append(" where FEntityNo=@FEntityNo");
            strSql.Append(" order by FIsTop desc,FPhraseID desc");
            SqlParameter[] parameters = { 
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar, 15) };
            parameters[0].Value = entityNo;

            ElingOA6_DSJCJ.Model.SysPhrase model = new ElingOA6_DSJCJ.Model.SysPhrase();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FPhrase"] != null && ds.Tables[0].Rows[0]["FPhrase"].ToString() != "")
                {
                    model.FPhrase = ds.Tables[0].Rows[0]["FPhrase"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FURL"] != null && ds.Tables[0].Rows[0]["FURL"].ToString() != "")
                {
                    model.FURL = ds.Tables[0].Rows[0]["FURL"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ElingOA6_DSJCJ.Model.SysPhrase DataRowToModel(DataRow row)
        {
            ElingOA6_DSJCJ.Model.SysPhrase model = new ElingOA6_DSJCJ.Model.SysPhrase();
            if (row != null)
            {
                if (row["FPhraseID"] != null && row["FPhraseID"].ToString() != "")
                {
                    model.FPhraseID = decimal.Parse(row["FPhraseID"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FPhrase"] != null)
                {
                    model.FPhrase = row["FPhrase"].ToString();
                }
                if (row["FURL"] != null)
                {
                    model.FURL = row["FURL"].ToString();
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }
                if (row["FPubIp"] != null)
                {
                    model.FPubIp = row["FPubIp"].ToString();
                }
                if (row["FEmplNo"] != null)
                {
                    model.FEmplNo = row["FEmplNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FPhraseNo"] != null)
                {
                    model.FPhraseNo = row["FPhraseNo"].ToString();
                }
                if (row["FIsTop"] != null && row["FIsTop"].ToString() != "")
                {
                    model.FIsTop = int.Parse(row["FIsTop"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FPhraseID,FEntityNo,FPhrase,FURL,FPubDate,FPubIp,FEmplNo,FDeptNo,FPhraseNo,FIsTop ");
            strSql.Append(" FROM t_SysPhrase ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
